 /**
 * 角色权限处理
 * Copyright (c) 2022 Lam
 */

import store from '@/store'
import {validPermiValue, hasRole} from '@/utils/permissionUtil';

export default {
  inserted(el, binding, vnode) {
    const { value } = binding

    if(!validPermiValue(value)){
      console.error(`v-hasRole label need roles values! Like v-hasRole="['grouperRole','userRole']" or v-hasRole='grouperRole,userRole'`);
      throw new Error(`请设置角色权限标签值(v-hasRole)`)
    }

    if (!hasRole(value)) {
      el.parentNode && el.parentNode.removeChild(el)
    }
  }
}
